unit untListCargo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, untListPadrao, DB, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls;

type
  TfrmListCargo = class(TfrmListPadrao)
    procedure btnIncluirClick(Sender: TObject);
    procedure btnAlterarClick(Sender: TObject);
    procedure btnExcluirClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure EdtPesquisarChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmListCargo: TfrmListCargo;

implementation

uses untCadCargo, untDm, untFuncoesListagem;

{$R *.dfm}

procedure TfrmListCargo.btnIncluirClick(Sender: TObject);
begin
  inherited;
  frmCadCargo.Tag := 1;
  frmCadCargo.ShowModal;
end;

procedure TfrmListCargo.btnAlterarClick(Sender: TObject);
begin
  inherited;
  frmCadCargo.Tag := 2;
  frmCadCargo.ShowModal;
end;

procedure TfrmListCargo.btnExcluirClick(Sender: TObject);
begin
  inherited;

  
  //---------------efetua a exclusao do registro
  if DM.CDSCargo.RecordCount = 0 then
    Exit;
  try
    if MessageDlg('Deseja Excluir o Cargo?', mtConfirmation, [mbYes,mbNo],0) = mrYes then
    begin
      DM.SDSComando.CommandText := 'DELETE FROM "Cargo" WHERE "cod_cargo" = :cod_cargo';
      DM.SDSComando.Params.ParamByName('cod_cargo').AsString := DM.CDSCargo.FieldByName('cod_cargo').AsString;
      DM.SDSComando.ExecSQL();
      DM.CDSCargo.Close;
      DM.CDSCargo.Open;

      //Atualiza o total
      EdtRegistros.Text := atualizaTotal('cargo');
    end;
  except
    if MessageDlg('Erro ao Excluir o Cargo', mtError, [mbOK],0) = mrOK then
      Exit;
  end;
  
end;

procedure TfrmListCargo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  DM.CDSCargo.Close;
  DM.SDSComando.Close;
  
end;

procedure TfrmListCargo.FormShow(Sender: TObject);
begin
  inherited;
  DM.CDSCargo.Open;
  EdtRegistros.Text := atualizaTotal('cargo');
end;

procedure TfrmListCargo.EdtPesquisarChange(Sender: TObject);
begin
  inherited;

  //verifica se o Campo nao esta vazio e procura o pedido pelo numero do pedido
  if Trim(EdtPesquisar.Text) <> '' then
  begin
    DM.CDSCargo.Locate('nome_cargo', EdtPesquisar.Text, [loCaseInsensitive,loPartialKey]);
  end;

end;

end.
